<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset = "UTF-8">
    <script src="{{url_for('static',filename='js/jquery.min.js')}}"></script>
    <script src="{{url_for('static',filename='js/scheduleTask.js')}}?{{version}}"></script>
    <script src="{{url_for('static',filename='js/bootstrap.min.js')}}"></script>
    <link rel="stylesheet" href="{{url_for('static',filename='css/bootstrap.min.css')}}">
    <title>定时任务</title>
    <style>
    .button{
        background-color: white;
        color: black;
        border: 2px solid #4CAF50;
    }

    .button:hover {
        background-color: #4CAF50;
        color: white;
    }
    .button[disabled] {
        opacity: 0.6;
        cursor: not-allowed;
    }
    </style>
</head>
<body>

        <nav class="navbar navbar-default" role="navigation">
    <div class="container-fluid">
    <div class="navbar-header">
        <a class="navbar-brand" href="#">盯盘宝后台管理系统</a>
    </div>
    <div>
        <ul class="nav navbar-nav">
            <li ><a href="{{ url_for('start_web') }}">首页</a></li>
            <li ><a href="{{ url_for('permission_manage') }}">权限配置</a></li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    管理员{{ session['admin'] if session['admin'] else "未登录" }}
                    <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="{{ url_for("login_out") }}">退出</a></li>
                </ul>
            </li>
        </ul>
    </div>
    </div>
</nav>
<div align="center">
<div class="btn-group btn-group-lg" role="group" aria-label="...">
    <div class="btn-group" role="group">
    <button id ="schedule_task" type="button" class="btn btn-default" onclick="changeDisplay('schedule_task')">定时任务</button>
    </div>

    <div class="btn-group" role="group">
    <button id ="tb_tick" type="button" class="btn btn-default" onclick="changeDisplay('tb_tick')">检查tb_tick数据</button>
    </div>

    <div class="btn-group" role="group">
    <button id ="tb_stock_sell" type="button" class="btn btn-default" onclick="changeDisplay('tb_stock_sell')">检查tb_stock_sell数据</button>
    </div>
</div>
</div>
<div id="strategy_system_thread_monitor" style="margin:auto; width:80%">

    <h3>定时任务执行情况</h3>
    <div style="margin:auto">

    <div id="schduleTaskDataTable" class="table table-striped table-bordered" cellspacing="0" width="80%">
    </div>
    </div>
</div>
<div align="center">
<div id ="check_tb_tick" style="border:1px solid rgb(68,113,188);width:1000px;height:500px;">
</div>
</div>
<div align="center">
<div id ="check_tb_stock_sell" style="border:1px solid rgb(68,113,188);width:1000px;height:1000px;overflow-y: auto;">
</div>
</div>
<script>

    function changeDisplay(type){
    $("#schedule_task").css("background-color","white");
    $("#tb_tick").css("background-color","white");
    $("#tb_stock_sell").css("background-color","white");
    var setColor="rgb(68,113,188)";
    $("#"+type).css("background-color",setColor);
    $("#strategy_system_thread_monitor").hide();
    $("#check_tb_tick").hide();
    $("#check_tb_stock_sell").hide();
    if (type =="schedule_task"){
        $("#strategy_system_thread_monitor").show();
    }else{
        $("#check_"+type).show();
    }
    }

    $.getJSON("/static/json/check_tb_tick.json?{{ version }}",function (result) {
        var obj = result;
        $("#check_tb_tick").append(obj.check_tb_tick);
    });
    $.getJSON("/static/json/tb_stock_sell_message.json?{{ version }}",function (result) {
        var obj = result;
        $("#check_tb_stock_sell").append(obj.message);
    });
        var schduleTaskDataTable = null;
         schduleTaskDataTable = jQuery("#schduleTaskDataTable").raytable({
            datasource: { data: [], keyfield: 'stock_code' },
            columns: [

            { field: "method_name", title: "任务名"},
            { field: "start_time", title: "计划执行时间"},
            { field: "finish_time", title: "执行完成时间"},
            { field: "is_exe_success", title: "是否成功执行"},
                { field: "exe_by_manual", title: "手动执行"},
            ],
            pagesize: 100,
            maxPageButtons: 5,
            rowNumbers: true
        });
         function refreshData() {
             $.ajax({
                 url:"/scheduleTaskData",
                 async:true,
                 success:function (result) {
                     var obj = JSON.parse(result);
                     var resultList = obj.resultList;
                     schduleTaskDataTable.data(resultList,'stock_code');
                 }
             })
         }
         refreshData();
         changeDisplay("schedule_task");

</script>

</body>
</html>